home *** CD-ROM | disk | FTP | other *** search
/ PLAYymate for OS/2 / Playmate for OS2.iso / p4os2040 / maze.c next >
Text File  |  1989-02-20  |  43KB  |  1,150 lines

  1. #define INCL_PM
  2. #include <os2.h>
  3. #include <stdlib.h>
  4. #include <malloc.h>
  5. #include "maze.h"
  6.  
  7. #define BACKTRACK_COLOR CLR_RED
  8. #define FLOOR_COLOR     CLR_BLACK
  9. #define SOLUTION_COLOR  CLR_GREEN
  10. #define WALL_COLOR      CLR_PALEGRAY
  11.  
  12. typedef struct ROWREC /* rr */
  13.                  {
  14.                    char          *pchRowPtr;
  15.                    struct ROWREC *prrPredecessorPtr;
  16.                    struct ROWREC *prrSuccessorPtr;
  17.                  } *pROWREC;
  18.  
  19. typedef struct STACK1REC /* s1 */
  20.                  {
  21.                    unsigned char    chIndex1;
  22.                    struct STACK1REC *ps1NextPtr;
  23.                  } *pSTACK1REC;
  24.  
  25. typedef struct STACK2REC /* s2 */
  26.                  {
  27.                    unsigned char    chIndex1;
  28.                    unsigned char    chIndex2;
  29.                    struct STACK2REC *ps2NextPtr;
  30.                  } *pSTACK2REC;
  31.  
  32. static void      ClearPaths(pROWREC *,int *);
  33. MRESULT EXPENTRY ClientWndProc(HWND,USHORT,MPARAM,MPARAM);
  34. static void      CreateMaze(int *,int *,pROWREC *,pROWREC *,
  35.                   int *);
  36. static void      DestroyMaze(pROWREC *,pROWREC *);
  37. MRESULT EXPENTRY HelpProc(HWND,USHORT,MPARAM,MPARAM);
  38. int cdecl        main(void);
  39. static void      OptionallyHaveComputerSolve(pROWREC *,
  40.                   pROWREC *,int *,int *,int *,int *);
  41. static void      PaintMaze(pROWREC *,int *,int *,int *,int *,int *,
  42.                   int *,int *,HPS,int *);
  43. static void      SizeMaze(int *,int *,pROWREC *,pROWREC *,
  44.                   int *,int *,int *,int *,int *,int *,int *,int *,int *,
  45.                   int *,int *,int *);
  46.  
  47. int cdecl main(void)
  48.   {
  49.     ULONG       ctldata;
  50.     HAB         hAB;
  51.     HMQ         hmq;
  52.     HWND        hwndClient;
  53.     HWND        hwndFrame;
  54.     QMSG        qmsg;
  55.     static CHAR szClientClass [] = "Maze";
  56.  
  57.     hAB=WinInitialize(NULL);
  58.     hmq=WinCreateMsgQueue(hAB,0);
  59.     WinRegisterClass(hAB,(PCH) szClientClass,(PFNWP) ClientWndProc,
  60.      CS_SYNCPAINT|CS_SIZEREDRAW,0);
  61.     ctldata=FCF_STANDARD & ~FCF_ICON;
  62.     hwndFrame=WinCreateStdWindow(HWND_DESKTOP,
  63.      WS_VISIBLE,&ctldata,
  64.      (PCH) szClientClass,NULL,0L,(HMODULE) NULL,ID_MAINMENU,
  65.      (HWND FAR *) &hwndClient);
  66.     WinShowWindow(hwndFrame,TRUE);
  67.     while (WinGetMsg(hAB,(PQMSG) &qmsg,(HWND) NULL,0,0))
  68.      WinDispatchMsg(hAB,(PQMSG) &qmsg);
  69.     WinDestroyWindow(hwndFrame);
  70.     WinDestroyMsgQueue(hmq);
  71.     WinTerminate(hAB);
  72.     return(0);
  73.   }
  74.  
  75. MRESULT EXPENTRY ClientWndProc(HWND hwnd,USHORT msg,MPARAM mp1,
  76.  MPARAM mp2)
  77.   {
  78.     static int     aiDeltaX [4] [24];
  79.     static int     aiDeltaY [4] [24];
  80.     static int     aiRN [8];
  81.            HPS     hPS;
  82.            HWND    hwndMenu;
  83.            int     iDeltaIndex1;
  84.     static int     iFatalError;
  85.     static int     iMagnitudeDeltaX;
  86.     static int     iMagnitudeDeltaY;
  87.     static int     iMaxX;
  88.     static int     iMaxY;
  89.     static int     iNumColumns;
  90.     static int     iNumRows;
  91.            int     iPassageFound;
  92.     static int     iSolved;
  93.     static int     iTwiceMagnitudeDeltaX;
  94.     static int     iTwiceMagnitudeDeltaY;
  95.     static int     iX;
  96.     static int     iXMax;
  97.     static int     iYMax;
  98.            int     iXNext;
  99.     static pROWREC prrCurrentPtr;
  100.            pROWREC prrNextPtr;
  101.     static pROWREC prrRowHead;
  102.     static pROWREC prrRowTail;
  103.     static POINTL  ptlPosition;
  104.            USHORT  usFrequency;
  105.  
  106.     switch (msg)
  107.       {
  108.         case WM_CREATE:
  109.           iSolved=TRUE;
  110.           iMaxX=0;
  111.           iMaxY=0;
  112.           CreateMaze(&aiDeltaX[0][0],&aiDeltaY[0][0],
  113.            &prrRowHead,&prrRowTail,&iFatalError);
  114.           break;
  115.         case WM_CHAR:
  116.           if ((! iSolved) && (! iFatalError)
  117.           &&  (iMaxX >= 20) && (iMaxY >= 20)
  118.           &&  (! ((ULONG) KC_KEYUP & (ULONG) mp1)))
  119.             {
  120.               iPassageFound=TRUE;
  121.               if ((ULONG) KC_CHAR & (ULONG) mp1)
  122.                 switch (SHORT1FROMMP(mp2))
  123.                   {
  124.                     case '8':
  125.                       iDeltaIndex1=1;
  126.                       break;
  127.                     case '4':
  128.                       iDeltaIndex1=2;
  129.                       break;
  130.                     case '6':
  131.                       iDeltaIndex1=0;
  132.                       break;
  133.                     case '2':
  134.                       iDeltaIndex1=3;
  135.                       break;
  136.                     default:
  137.                       iPassageFound=FALSE;
  138.                       break;
  139.                   }
  140.               else
  141.                 {
  142.                   if ((ULONG) KC_VIRTUALKEY & (ULONG) mp1)
  143.                     switch (SHORT2FROMMP(mp2))
  144.                       {
  145.                         case VK_UP:
  146.                           iDeltaIndex1=1;
  147.                           break;
  148.                         case VK_LEFT:
  149.                           iDeltaIndex1=2;
  150.                           break;
  151.                         case VK_RIGHT:
  152.                           iDeltaIndex1=0;
  153.                           break;
  154.                         case VK_DOWN:
  155.                           iDeltaIndex1=3;
  156.                           break;
  157.                           break;
  158.                         default:
  159.                           iPassageFound=FALSE;
  160.                           break;
  161.                       }
  162.                 }
  163.               if (iPassageFound)
  164.                 {
  165.                   switch (aiDeltaY[iDeltaIndex1][0])
  166.                     {
  167.                       case -1:
  168.                         iXNext=iX;
  169.                         prrNextPtr=prrCurrentPtr->prrPredecessorPtr;
  170.                         break;
  171.                       case 1:
  172.                         iXNext=iX;
  173.                         prrNextPtr=prrCurrentPtr->prrSuccessorPtr;
  174.                         break;
  175.                       default:
  176.                         iXNext=iX+aiDeltaX[iDeltaIndex1][0];
  177.                         prrNextPtr=prrCurrentPtr;
  178.                         break;
  179.                     }
  180.                   if (*((prrNextPtr->pchRowPtr)+iXNext) == 'W')
  181.                     iPassageFound=FALSE;
  182.                   else
  183.                     if (prrNextPtr->prrPredecessorPtr == NULL)
  184.                       iPassageFound=FALSE;
  185.                     else
  186.                       {
  187.                         hPS=WinGetPS(hwnd);
  188.                         GpiMove(hPS,&ptlPosition);
  189.                         if (*((prrNextPtr->pchRowPtr)+iXNext) == 'S')
  190.                           {
  191.                             GpiSetColor(hPS,BACKTRACK_COLOR);
  192.                             *((prrCurrentPtr->pchRowPtr)+iX)='A';
  193.                             *((prrNextPtr->pchRowPtr)+iXNext)='A';
  194.                           }
  195.                         else
  196.                           {
  197.                             GpiSetColor(hPS,SOLUTION_COLOR);
  198.                             *((prrNextPtr->pchRowPtr)+iXNext)='S';
  199.                           }
  200.                         switch (aiDeltaY[iDeltaIndex1][0])
  201.                           {
  202.                             case -1:
  203.                               prrNextPtr=prrNextPtr->prrPredecessorPtr;
  204.                               ptlPosition.y-=iTwiceMagnitudeDeltaY;
  205.                               break;
  206.                             case 1:
  207.                               prrNextPtr=prrNextPtr->prrSuccessorPtr;
  208.                               if (prrNextPtr == NULL)
  209.                                 ptlPosition.y+=iMagnitudeDeltaY;
  210.                               else
  211.                                 ptlPosition.y+=iTwiceMagnitudeDeltaY;
  212.                               break;
  213.                             default:
  214.                               iXNext+=aiDeltaX[iDeltaIndex1][0];
  215.                               ptlPosition.x+=(iTwiceMagnitudeDeltaX
  216.                                *aiDeltaX[iDeltaIndex1][0]);
  217.                               break;
  218.                           }
  219.                         GpiLine(hPS,&ptlPosition);
  220.                         WinReleasePS(hPS);
  221.                         prrCurrentPtr=prrNextPtr;
  222.                         iX=iXNext;
  223.                         if (prrCurrentPtr == NULL)
  224.                           {
  225.                             iSolved=TRUE;
  226.                             usFrequency=10;
  227.                             for (iDeltaIndex1=1; iDeltaIndex1 <= 100;
  228.                              iDeltaIndex1++)
  229.                               {
  230.                                 DosBeep(usFrequency,56);
  231.                                 usFrequency+=10;
  232.                               }
  233.                           }
  234.                         else
  235.                           *((prrCurrentPtr->pchRowPtr)+iX)='S';
  236.                       }
  237.                 }
  238.               if ((! iPassageFound)
  239.               &&  (SHORT2FROMMP(mp2) != VK_NUMLOCK)
  240.               &&  (SHORT2FROMMP(mp2) != VK_ALT))
  241.                 DosBeep(120,333);
  242.             }
  243.           return((MRESULT) 1);
  244.           break;
  245.         case WM_COMMAND:
  246.           hwndMenu=WinWindowFromID(WinQueryWindow(hwnd,QW_PARENT,FALSE),
  247.            FID_MENU);
  248.           switch (COMMANDMSG(&msg)->cmd)
  249.             {
  250.               case IDM_CLEAR:
  251.                 if (! iFatalError)
  252.                   {
  253.                     ClearPaths(&prrRowHead,&iNumColumns);
  254.                     ptlPosition.x=iMagnitudeDeltaX;
  255.                     ptlPosition.y=iMagnitudeDeltaY;
  256.                     prrCurrentPtr=prrRowHead->prrSuccessorPtr;
  257.                     iX=1;
  258.                     iSolved=FALSE;
  259.                   }
  260.                 WinInvalidateRect(hwnd,NULL,FALSE);
  261.                 break;
  262.               case IDM_NEW:
  263.                 if ((iMaxX >= 20) && (iMaxY >= 20))
  264.                   {
  265.                     SizeMaze(&aiDeltaX[0][0],&aiDeltaY[0][0],
  266.                      &prrRowHead,&prrRowTail,
  267.                      &iMagnitudeDeltaX,&iMagnitudeDeltaY,
  268.                      &iMaxX,&iMaxY,&iNumColumns,&iNumRows,&aiRN[0],
  269.                      &iTwiceMagnitudeDeltaX,&iTwiceMagnitudeDeltaY,
  270.                      &iXMax,&iYMax,&iFatalError);
  271.                     if (! iFatalError)
  272.                       {
  273.                         ptlPosition.x=iMagnitudeDeltaX;
  274.                         ptlPosition.y=iMagnitudeDeltaY;
  275.                         prrCurrentPtr=prrRowHead->prrSuccessorPtr;
  276.                         iX=1;
  277.                       }
  278.                   }
  279.                 iSolved=FALSE;
  280.                 WinInvalidateRect(hwnd,NULL,FALSE);
  281.                 break;
  282.               case IDM_SOLVE:
  283.                 if ((! iFatalError) && (iMaxX >= 20) && (iMaxY >= 20))
  284.                   {
  285.                     ClearPaths(&prrRowHead,&iNumColumns);
  286.                     OptionallyHaveComputerSolve(&prrRowHead,&prrRowTail,
  287.                      &aiDeltaX[0][0],&aiDeltaY[0][0],&iNumColumns,
  288.                      &iFatalError);
  289.                     iSolved=TRUE;
  290.                   }
  291.                 WinInvalidateRect(hwnd,NULL,FALSE);
  292.                 break;
  293.               case IDM_HELP:
  294.                 WinDlgBox(HWND_DESKTOP,hwnd,HelpProc,NULL,IDD_HELPBOX,
  295.                  NULL);
  296.                 break;
  297.               default:
  298.                 break;
  299.             }
  300.           break;
  301.         case WM_SIZE:
  302.           iSolved=FALSE;
  303.           iMaxX=SHORT1FROMMP(mp2)-1;
  304.           iMaxY=SHORT2FROMMP(mp2)-1;
  305.           if ((iMaxX >= 20) && (iMaxY >= 20))
  306.             {
  307.               SizeMaze(&aiDeltaX[0][0],&aiDeltaY[0][0],&prrRowHead,
  308.                &prrRowTail,&iMagnitudeDeltaX,&iMagnitudeDeltaY,
  309.                &iMaxX,&iMaxY,&iNumColumns,&iNumRows,&aiRN[0],
  310.                &iTwiceMagnitudeDeltaX,&iTwiceMagnitudeDeltaY,
  311.                &iXMax,&iYMax,&iFatalError);
  312.               if (! iFatalError)
  313.                 {
  314.                   ptlPosition.x=iMagnitudeDeltaX;
  315.                   ptlPosition.y=iMagnitudeDeltaY;
  316.                   prrCurrentPtr=prrRowHead->prrSuccessorPtr;
  317.                   iX=1;
  318.                 }
  319.               iSolved=FALSE;
  320.             }
  321.           break;
  322.         case WM_ERASEBACKGROUND:
  323.           return(TRUE);
  324.           break;
  325.         case WM_PAINT:
  326.           hPS=WinBeginPaint(hwnd,(HPS) NULL,(PWRECT) NULL);
  327.           if ((iMaxX >= 20) && (iMaxY >= 20))
  328.             PaintMaze(&prrRowHead,&iNumColumns,&iMagnitudeDeltaX,
  329.              &iMagnitudeDeltaY,&iTwiceMagnitudeDeltaX,
  330.              &iTwiceMagnitudeDeltaY,&iXMax,&iYMax,hPS,&iFatalError);
  331.           WinEndPaint(hPS);
  332.           break;
  333.         case WM_DESTROY:
  334.           DestroyMaze(&prrRowHead,&prrRowTail);
  335.           break;
  336.         default:
  337.           return(WinDefWindowProc(hwnd,msg,mp1,mp2));
  338.           break;
  339.       }
  340.     return(0L);
  341.   }
  342.  
  343. MRESULT EXPENTRY HelpProc(HWND hwnd,USHORT msg,MPARAM mp1,MPARAM mp2)
  344.   {
  345.     switch (msg)
  346.       {
  347.         case WM_COMMAND:
  348.           switch (COMMANDMSG(&msg)->cmd)
  349.             {
  350.               case DID_OK:
  351.               case DID_CANCEL:
  352.                 WinDismissDlg(hwnd,TRUE);
  353.                 break;
  354.               default:
  355.                 break;
  356.             }
  357.           break;
  358.         default:
  359.           return(WinDefDlgProc(hwnd,msg,mp1,mp2));
  360.       }
  361.     return(0);
  362.   }
  363.  
  364. static void CreateMaze(piDeltaX,piDeltaY,pprrRowHead,pprrRowTail,
  365.  piFatalError)
  366.   int     *piDeltaX;
  367.   int     *piDeltaY;
  368.   pROWREC *pprrRowHead;
  369.   pROWREC *pprrRowTail;
  370.   int     *piFatalError;
  371.     {
  372.       int iDeltaIndex1a;
  373.       int iDeltaIndex1b;
  374.       int iDeltaIndex1c;
  375.       int iDeltaIndex1d;
  376.       int iDeltaIndex2;
  377.  
  378.       *piFatalError=FALSE;
  379.       *piDeltaX=1;
  380.       *(piDeltaY+24)=1;
  381.       *(piDeltaX+48)=-1;
  382.       *(piDeltaY+72)=-1;
  383.       *piDeltaY=0;
  384.       *(piDeltaX+24)=0;
  385.       *(piDeltaY+48)=0;
  386.       *(piDeltaX+72)=0;
  387.       iDeltaIndex2=-1;
  388.       for (iDeltaIndex1a=0; iDeltaIndex1a < 4; iDeltaIndex1a++)
  389.         for (iDeltaIndex1b=0; iDeltaIndex1b < 4; iDeltaIndex1b++)
  390.           if (iDeltaIndex1a != iDeltaIndex1b)
  391.             for (iDeltaIndex1c=0; iDeltaIndex1c < 4;
  392.              iDeltaIndex1c++)
  393.               if ((iDeltaIndex1a != iDeltaIndex1c)
  394.               &&  (iDeltaIndex1b != iDeltaIndex1c))
  395.                 for (iDeltaIndex1d=0; iDeltaIndex1d < 4;
  396.                  iDeltaIndex1d++)
  397.                   if ((iDeltaIndex1a != iDeltaIndex1d)
  398.                   &&  (iDeltaIndex1b != iDeltaIndex1d)
  399.                   &&  (iDeltaIndex1c != iDeltaIndex1d))
  400.                     {
  401.                       iDeltaIndex2=iDeltaIndex2+1;
  402.                       *(piDeltaX+(24*iDeltaIndex1a+iDeltaIndex2))
  403.                        =*piDeltaX;
  404.                       *(piDeltaY+(24*iDeltaIndex1a+iDeltaIndex2))
  405.                        =*piDeltaY;
  406.                       *(piDeltaX+(24*iDeltaIndex1b+iDeltaIndex2))
  407.                        =*(piDeltaX+24);
  408.                       *(piDeltaY+(24*iDeltaIndex1b+iDeltaIndex2))
  409.                        =*(piDeltaY+24);
  410.                       *(piDeltaX+(24*iDeltaIndex1c+iDeltaIndex2))
  411.                        =*(piDeltaX+48);
  412.                       *(piDeltaY+(24*iDeltaIndex1c+iDeltaIndex2))
  413.                        =*(piDeltaY+48);
  414.                       *(piDeltaX+(24*iDeltaIndex1d+iDeltaIndex2))
  415.                        =*(piDeltaX+72);
  416.                       *(piDeltaY+(24*iDeltaIndex1d+iDeltaIndex2))
  417.                        =*(piDeltaY+72);
  418.                     }
  419.       *pprrRowHead=NULL;
  420.       *pprrRowTail=NULL;
  421.       return;
  422.     }
  423.  
  424. static void SizeMaze(piDeltaX,piDeltaY,pprrRowHead,pprrRowTail,
  425.  piMagnitudeDeltaX,piMagnitudeDeltaY,piMaxX,piMaxY,piNumColumns,
  426.  piNumRows,piRN,piTwiceMagnitudeDeltaX,piTwiceMagnitudeDeltaY,
  427.  piXMax,piYMax,piFatalError)
  428.   int     *piDeltaX;
  429.   int     *piDeltaY;
  430.   pROWREC *pprrRowHead;
  431.   pROWREC *pprrRowTail;
  432.   int     *piMagnitudeDeltaX;
  433.   int     *piMagnitudeDeltaY;
  434.   int     *piMaxX;
  435.   int     *piMaxY;
  436.   int     *piNumColumns;
  437.   int     *piNumRows;
  438.   int     *piRN;
  439.   int     *piTwiceMagnitudeDeltaX;
  440.   int     *piTwiceMagnitudeDeltaY;
  441.   int     *piXMax;
  442.   int     *piYMax;
  443.   int     *piFatalError;
  444.     {
  445.       DATETIME   dateSeed;
  446.       int        iColumnNum;
  447.       int        iDeltaIndex1;
  448.       int        iDeltaIndex2;
  449.       int        iDigit;
  450.       int        iDigitNum;
  451.       int        iFinished;
  452.       int        iRecurse;
  453.       int        iRNIndex1;
  454.       int        iRNIndex2;
  455.       int        iRowNum;
  456.       int        iSum;
  457.       int        iTemInt;
  458.       int        iX;
  459.       int        iXNext;
  460.       int        iXOut;
  461.       int        iY;
  462.       int        iYOut;
  463.       char       *pchColumnPtr;
  464.       pROWREC    prrCurrentPtr;
  465.       pROWREC    prrNextPtr;
  466.       pROWREC    prrPreviousPtr;
  467.       pSTACK2REC ps2StackHead;
  468.       pSTACK2REC ps2StackPtr;
  469.  
  470.       DosGetDateTime(&dateSeed);
  471.       *piRN=dateSeed.year%29;
  472.       *(piRN+1)=dateSeed.month;
  473.       *(piRN+2)=dateSeed.day%29;
  474.       *(piRN+3)=dateSeed.hours;
  475.       *(piRN+4)=dateSeed.minutes%29;
  476.       *(piRN+5)=dateSeed.seconds%29;
  477.       *(piRN+6)=dateSeed.hundredths%29;
  478.       *(piRN+7)=0;
  479.       *piNumColumns=(*piMaxX)/10;
  480.       *piNumRows=(*piMaxY)/10;
  481.       *piMagnitudeDeltaX=(*piMaxX)/(*piNumColumns)/2;
  482.       *piTwiceMagnitudeDeltaX
  483.        =(*piMagnitudeDeltaX)+(*piMagnitudeDeltaX);
  484.       *piMagnitudeDeltaY=(*piMaxY)/(*piNumRows)/2;
  485.       *piTwiceMagnitudeDeltaY
  486.        =(*piMagnitudeDeltaY)+(*piMagnitudeDeltaY);
  487.       *piXMax=*piTwiceMagnitudeDeltaX*(*piNumColumns);
  488.       *piYMax=*piTwiceMagnitudeDeltaY*(*piNumRows);
  489.       while (*pprrRowHead != NULL)
  490.         {
  491.           free((*pprrRowHead)->pchRowPtr);
  492.           prrPreviousPtr=*pprrRowHead;
  493.           *pprrRowHead=(*pprrRowHead)->prrSuccessorPtr;
  494.           free((char *) prrPreviousPtr);
  495.         }
  496.       if ((*pprrRowHead=(struct ROWREC *)
  497.        malloc((unsigned) sizeof(struct ROWREC))) == NULL)
  498.         *piFatalError=TRUE;
  499.       else
  500.         {
  501.           (*pprrRowHead)->prrPredecessorPtr=NULL;
  502.           (*pprrRowHead)->prrSuccessorPtr=NULL;
  503.           *pprrRowTail=*pprrRowHead;
  504.           if (((*pprrRowHead)->pchRowPtr=
  505.            malloc((unsigned) 2*(*piNumColumns)+1)) == NULL)
  506.             *piFatalError=TRUE;
  507.           else
  508.             {
  509.               pchColumnPtr=(*pprrRowHead)->pchRowPtr;
  510.               for (iColumnNum=0; iColumnNum < 2*(*piNumColumns)+1;
  511.                iColumnNum++)
  512.                 {
  513.                   *pchColumnPtr='W';
  514.                   pchColumnPtr++;
  515.                 }
  516.             }
  517.         }
  518.       iRowNum=1;
  519.       while ((iRowNum <= *piNumRows) && (! *piFatalError))
  520.         {
  521.           if ((prrCurrentPtr=(struct ROWREC *)
  522.            malloc((unsigned) sizeof(struct ROWREC))) == NULL)
  523.             *piFatalError=TRUE;
  524.           else
  525.             {
  526.               (*pprrRowTail)->prrSuccessorPtr=prrCurrentPtr;
  527.               prrCurrentPtr->prrPredecessorPtr=*pprrRowTail;
  528.               prrCurrentPtr->prrSuccessorPtr=NULL;
  529.               *pprrRowTail=prrCurrentPtr;
  530.               if ((prrCurrentPtr->pchRowPtr=
  531.                malloc((unsigned) 2*(*piNumColumns)+1)) == NULL)
  532.                 *piFatalError=TRUE;
  533.               else
  534.                 {
  535.                   pchColumnPtr=prrCurrentPtr->pchRowPtr;
  536.                   for (iColumnNum=0; iColumnNum < 2*(*piNumColumns)+1;
  537.                    iColumnNum++)
  538.                     {
  539.                       *pchColumnPtr='W';
  540.                       pchColumnPtr++;
  541.                     }
  542.                 }
  543.             }
  544.           if ((prrCurrentPtr=(struct ROWREC *)
  545.            malloc((unsigned) sizeof(struct ROWREC))) == NULL)
  546.             *piFatalError=TRUE;
  547.           else
  548.             {
  549.               (*pprrRowTail)->prrSuccessorPtr=prrCurrentPtr;
  550.               prrCurrentPtr->prrPredecessorPtr=*pprrRowTail;
  551.               prrCurrentPtr->prrSuccessorPtr=NULL;
  552.               *pprrRowTail=prrCurrentPtr;
  553.               if ((prrCurrentPtr->pchRowPtr=
  554.                malloc((unsigned) 2*(*piNumColumns)+1)) == NULL)
  555.                 *piFatalError=TRUE;
  556.               else
  557.                 {
  558.                   pchColumnPtr=prrCurrentPtr->pchRowPtr;
  559.                   for (iColumnNum=0; iColumnNum < 2*(*piNumColumns)+1;
  560.                    iColumnNum++)
  561.                     {
  562.                       *pchColumnPtr='W';
  563.                       pchColumnPtr++;
  564.                     }
  565.                 }
  566.             }
  567.           iRowNum++;
  568.         }
  569.       iSum=0;
  570.       for (iDigitNum=1; iDigitNum <= 3; iDigitNum++)
  571.         {
  572.           iDigit=*piRN;
  573.           iRNIndex1=0;
  574.           for (iRNIndex2=1; iRNIndex2 < 8; iRNIndex2++)
  575.             {
  576.               iTemInt=*(piRN+iRNIndex2);
  577.               *(piRN+iRNIndex1)=iTemInt;
  578.               iRNIndex1++;
  579.               iDigit+=iTemInt;
  580.               if (iDigit >= 29)
  581.                 iDigit-=29;
  582.             }
  583.           *(piRN+7)=iDigit;
  584.           iSum=29*iSum+iDigit;
  585.         }
  586.       iX=2*(iSum%(*piNumColumns))+1;
  587.       iSum=0;
  588.       for (iDigitNum=1; iDigitNum <= 3; iDigitNum++)
  589.         {
  590.           iDigit=*piRN;
  591.           iRNIndex1=0;
  592.           for (iRNIndex2=1; iRNIndex2 < 8; iRNIndex2++)
  593.             {
  594.               iTemInt=*(piRN+iRNIndex2);
  595.               *(piRN+iRNIndex1)=iTemInt;
  596.               iRNIndex1++;
  597.               iDigit+=iTemInt;
  598.               if (iDigit >= 29)
  599.                 iDigit-=29;
  600.             }
  601.           *(piRN+7)=iDigit;
  602.           iSum=29*iSum+iDigit;
  603.         }
  604.       iY=2*(iSum%(*piNumRows))+1;
  605.       prrCurrentPtr=*pprrRowHead;
  606.       for (iYOut=0; iYOut < iY; iYOut++)
  607.         prrCurrentPtr=prrCurrentPtr->prrSuccessorPtr;
  608.       iFinished=FALSE;
  609.       iRecurse=TRUE;
  610.       ps2StackHead=NULL;
  611.       while ((! iFinished) && (! *piFatalError))
  612.         {
  613.           if (iRecurse)
  614.             {
  615.               *((prrCurrentPtr->pchRowPtr)+iX)=' ';
  616.               iDeltaIndex1=0;
  617.               do
  618.                 {
  619.                   iDeltaIndex2=*piRN;
  620.                   iRNIndex1=0;
  621.                   for (iRNIndex2=1; iRNIndex2 < 8; iRNIndex2++)
  622.                     {
  623.                       iTemInt=*(piRN+iRNIndex2);
  624.                       *(piRN+iRNIndex1)=iTemInt;
  625.                       iRNIndex1++;
  626.                       iDeltaIndex2+=iTemInt;
  627.                       if (iDeltaIndex2 >= 29)
  628.                         iDeltaIndex2-=29;
  629.                     }
  630.                   *(piRN+7)=iDeltaIndex2;
  631.                 }
  632.               while (iDeltaIndex2 >= 24);
  633.               iRecurse=FALSE;
  634.             }
  635.             while ((iDeltaIndex1 < 4)
  636.             &&     (! iRecurse)
  637.             &&     (! *piFatalError))
  638.               {
  639.                 iXNext
  640.                  =iX+2*(*(piDeltaX+(24*iDeltaIndex1+iDeltaIndex2)));
  641.                 if ((iXNext <= 0) || (iXNext >= 2*(*piNumColumns)))
  642.                   iDeltaIndex1++;
  643.                 else
  644.                   {
  645.                     switch (*(piDeltaY+(24*iDeltaIndex1+iDeltaIndex2)))
  646.                       {
  647.                         case -1:
  648.                           prrNextPtr
  649.                            =(prrCurrentPtr->prrPredecessorPtr)->
  650.                            prrPredecessorPtr;
  651.                           break;
  652.                         case 1:
  653.                           prrNextPtr=(prrCurrentPtr->prrSuccessorPtr)->
  654.                            prrSuccessorPtr;
  655.                           break;
  656.                         default:
  657.                           prrNextPtr=prrCurrentPtr;
  658.                           break;
  659.                       }
  660.                     if (prrNextPtr == NULL)
  661.                       iDeltaIndex1++;
  662.                     else
  663.                       {
  664.                         if (*((prrNextPtr->pchRowPtr)+iXNext) == 'W')
  665.                           {
  666.                             if (iX == iXNext)
  667.                               if ((*(piDeltaY
  668.                                +(24*iDeltaIndex1+iDeltaIndex2)))
  669.                                == 1)
  670.                                 *(((prrCurrentPtr->prrSuccessorPtr)
  671.                                  ->pchRowPtr)+iX)=' ';
  672.                               else
  673.                                 *(((prrCurrentPtr->prrPredecessorPtr)
  674.                                  ->pchRowPtr)+iX)=' ';
  675.                             else
  676.                               {
  677.                                 iXOut=(iX+iXNext)/2;
  678.                                 *((prrCurrentPtr->pchRowPtr)+iXOut)=' ';
  679.                               }
  680.                             iX=iXNext;
  681.                             prrCurrentPtr=prrNextPtr;
  682.                             if ((ps2StackPtr=
  683.                              (struct STACK2REC *) malloc(
  684.                              (unsigned) sizeof(struct STACK2REC)))
  685.                              == NULL)
  686.                               *piFatalError=TRUE;
  687.                             else
  688.                               {
  689.                                 ps2StackPtr->ps2NextPtr=ps2StackHead;
  690.                                 ps2StackHead=ps2StackPtr;
  691.                                 ps2StackHead->chIndex1
  692.                                  =(unsigned char) iDeltaIndex1;
  693.                                 ps2StackHead->chIndex2
  694.                                  =(unsigned char) iDeltaIndex2;
  695.                                 iRecurse=TRUE;
  696.                               }
  697.                           }
  698.                         else
  699.                           iDeltaIndex1++;
  700.                       }
  701.                   }
  702.               }
  703.             if ((! iRecurse) && (! *piFatalError))
  704.               {
  705.                 iDeltaIndex1=(int) ps2StackHead->chIndex1;
  706.                 iDeltaIndex2=(int) ps2StackHead->chIndex2;
  707.                 ps2StackPtr=ps2StackHead;
  708.                 ps2StackHead=ps2StackHead->ps2NextPtr;
  709.                 free((char *) ps2StackPtr);
  710.                 if (ps2StackHead == NULL)
  711.                   iFinished=TRUE;
  712.                 else
  713.                   switch (*(piDeltaY+(24*iDeltaIndex1+iDeltaIndex2)))
  714.                     {
  715.                       case -1:
  716.                         prrCurrentPtr=(prrCurrentPtr->prrSuccessorPtr)->
  717.                          prrSuccessorPtr;
  718.                         break;
  719.                       case 1:
  720.                         prrCurrentPtr
  721.                          =(prrCurrentPtr->prrPredecessorPtr)->
  722.                          prrPredecessorPtr;
  723.                         break;
  724.                       default:
  725.                         iX-=
  726.                      (2*(*(piDeltaX+(24*iDeltaIndex1+iDeltaIndex2))));
  727.                         break;
  728.                     }
  729.               }
  730.         }
  731.       if (! *piFatalError)
  732.         {
  733.           *(((*pprrRowHead)->pchRowPtr)+1)='S';
  734.           *((((*pprrRowHead)->prrSuccessorPtr)->pchRowPtr)+1)='S';
  735.           *(((*pprrRowTail)->pchRowPtr)+(2*(*piNumColumns)-1))=' ';
  736.         }
  737.       return;
  738.     }
  739.  
  740. static void PaintMaze(pprrRowHead,piNumColumns,piMagnitudeDeltaX,
  741.  piMagnitudeDeltaY,piTwiceMagnitudeDeltaX,piTwiceMagnitudeDeltaY,
  742.  piXMax,piYMax,hPS,piFatalError)
  743.   pROWREC *pprrRowHead;
  744.   int         *piNumColumns;
  745.   int         *piMagnitudeDeltaX;
  746.   int         *piMagnitudeDeltaY;
  747.   int         *piTwiceMagnitudeDeltaX;
  748.   int         *piTwiceMagnitudeDeltaY;
  749.   int         *piXMax;
  750.   int         *piYMax;
  751.   HPS         hPS;
  752.   int         *piFatalError;
  753.     {
  754.       char    chPenColor;
  755.       int     iColumnNum;
  756.       int     iEven;
  757.       char    *pchPixelPtr;
  758.       pROWREC prrCurrentPtr;
  759.       POINTL  ptlEndingPosition;
  760.       POINTL  ptlStartingPosition;
  761.  
  762.       if (* piFatalError)
  763.         {
  764.           GpiSetColor(hPS,BACKTRACK_COLOR);
  765.           ptlStartingPosition.x=0;
  766.           ptlStartingPosition.y=0;
  767.           ptlEndingPosition.x=*piXMax;
  768.           ptlEndingPosition.y=*piYMax;
  769.           GpiMove(hPS,&ptlStartingPosition);
  770.           GpiBox(hPS,DRO_FILL,&ptlEndingPosition,(long) 0,(long) 0);
  771.           DosBeep(60,333);
  772.         }
  773.       else
  774.         {
  775.           GpiSetColor(hPS,FLOOR_COLOR);
  776.           ptlStartingPosition.x=0;
  777.           ptlStartingPosition.y=0;
  778.           ptlEndingPosition.x=*piXMax;
  779.           ptlEndingPosition.y=*piYMax;
  780.           GpiMove(hPS,&ptlStartingPosition);
  781.           GpiBox(hPS,DRO_FILL,&ptlEndingPosition,(long) 0,(long) 0);
  782.           prrCurrentPtr=*pprrRowHead;
  783.           iEven=TRUE;
  784.           ptlStartingPosition.y=0;
  785.           ptlEndingPosition.y=0;
  786.           while (prrCurrentPtr != NULL)
  787.             {
  788.               if (iEven)
  789.                 {
  790.                   pchPixelPtr=(prrCurrentPtr->pchRowPtr)+1;
  791.                   ptlStartingPosition.x=0;
  792.                   ptlEndingPosition.x=(*piTwiceMagnitudeDeltaX);
  793.                   GpiSetColor(hPS,WALL_COLOR);
  794.                   chPenColor=' ';
  795.                   for (iColumnNum=1; iColumnNum <= *piNumColumns;
  796.                    iColumnNum++)
  797.                     {
  798.                       if (*pchPixelPtr == 'W')
  799.                         {
  800.                           if (chPenColor != 'W')
  801.                             {
  802.                               chPenColor='W';
  803.                               GpiMove(hPS,&ptlStartingPosition);
  804.                             }
  805.                         }
  806.                       else
  807.                         {
  808.                           if (chPenColor == 'W')
  809.                             {
  810.                               GpiLine(hPS,&ptlStartingPosition);
  811.                               chPenColor=' ';
  812.                             }
  813.                         }
  814.                       ptlStartingPosition.x=ptlEndingPosition.x;
  815.                       ptlEndingPosition.x+=(*piTwiceMagnitudeDeltaX);
  816.                       pchPixelPtr+=2;
  817.                     }
  818.                   if (chPenColor == 'W')
  819.                     GpiLine(hPS,&ptlStartingPosition);
  820.                   ptlStartingPosition.y+=(*piMagnitudeDeltaY);
  821.                   ptlEndingPosition.y=ptlStartingPosition.y;
  822.                 }
  823.               else
  824.                 {
  825.                   pchPixelPtr=(prrCurrentPtr->pchRowPtr);
  826.                   ptlStartingPosition.x=-(*piMagnitudeDeltaX);
  827.                   ptlEndingPosition.x=(*piMagnitudeDeltaX);
  828.                   chPenColor=' ';
  829.                   for (iColumnNum=1; iColumnNum <= *piNumColumns;
  830.                    iColumnNum++)
  831.                     {
  832.                       switch (*pchPixelPtr)
  833.                         {
  834.                           case 'A':
  835.                             if (chPenColor != 'A')
  836.                               {
  837.                                 if (chPenColor != ' ')
  838.                                   GpiLine(hPS,&ptlStartingPosition);
  839.                                 chPenColor='A';
  840.                                 GpiSetColor(hPS,BACKTRACK_COLOR);
  841.                                 GpiMove(hPS,&ptlStartingPosition);
  842.                               }
  843.                             break;
  844.                           case 'S':
  845.                             if (chPenColor != 'S')
  846.                               {
  847.                                 if (chPenColor != ' ')
  848.                                   GpiLine(hPS,&ptlStartingPosition);
  849.                                 chPenColor='S';
  850.                                 GpiSetColor(hPS,SOLUTION_COLOR);
  851.                                 GpiMove(hPS,&ptlStartingPosition);
  852.                               }
  853.                             break;
  854.                           default:
  855.                             if (chPenColor != ' ')
  856.                               {
  857.                                 GpiLine(hPS,&ptlStartingPosition);
  858.                                 chPenColor=' ';
  859.                               }
  860.                             break;
  861.                         }
  862.                       ptlStartingPosition.x=ptlEndingPosition.x;
  863.                       ptlEndingPosition.x+=(*piTwiceMagnitudeDeltaX);
  864.                       pchPixelPtr+=2;
  865.                     }
  866.                   if (chPenColor != ' ')
  867.                     GpiLine(hPS,&ptlStartingPosition);
  868.                   ptlStartingPosition.y+=(*piMagnitudeDeltaY);
  869.                   ptlEndingPosition.y=ptlStartingPosition.y;
  870.                 }
  871.               iEven=! iEven;
  872.               prrCurrentPtr=prrCurrentPtr->prrSuccessorPtr;
  873.             }
  874.           ptlStartingPosition.x=0;
  875.           ptlEndingPosition.x=0;
  876.           for (iColumnNum=1; iColumnNum <= *piNumColumns;
  877.            iColumnNum++)
  878.             {
  879.               ptlStartingPosition.y=0;
  880.               ptlEndingPosition.y=*piTwiceMagnitudeDeltaY;
  881.               prrCurrentPtr=*pprrRowHead;
  882.               iEven=TRUE;
  883.               chPenColor=' ';
  884.               GpiSetColor(hPS,WALL_COLOR);
  885.               while (prrCurrentPtr != NULL)
  886.                 {
  887.                   if (! iEven)
  888.                     {
  889.                       pchPixelPtr
  890.                        =(prrCurrentPtr->pchRowPtr)+2*(iColumnNum-1);
  891.                       if (*pchPixelPtr == 'W')
  892.                         {
  893.                           if (chPenColor != 'W')
  894.                             {
  895.                               chPenColor='W';
  896.                               GpiMove(hPS,&ptlStartingPosition);
  897.                             }
  898.                         }
  899.                       else
  900.                         {
  901.                           if (chPenColor == 'W')
  902.                             {
  903.                               GpiLine(hPS,&ptlStartingPosition);
  904.                               chPenColor=' ';
  905.                             }
  906.                         }
  907.                       ptlStartingPosition.y=ptlEndingPosition.y;
  908.                       ptlEndingPosition.y+=(*piTwiceMagnitudeDeltaY);
  909.                     }
  910.                   iEven=! iEven;
  911.                   prrCurrentPtr=prrCurrentPtr->prrSuccessorPtr;
  912.                 }
  913.               if (chPenColor == 'W')
  914.                 GpiLine(hPS,&ptlStartingPosition);
  915.               ptlStartingPosition.x+=(*piMagnitudeDeltaX);
  916.               ptlEndingPosition.x=ptlStartingPosition.x;
  917.               ptlStartingPosition.y=0;
  918.               ptlEndingPosition.y=(*piMagnitudeDeltaY);
  919.               prrCurrentPtr=*pprrRowHead;
  920.               iEven=TRUE;
  921.               chPenColor=' ';
  922.               while (prrCurrentPtr != NULL)
  923.                 {
  924.                   if (iEven)
  925.                     {
  926.                       pchPixelPtr
  927.                        =(prrCurrentPtr->pchRowPtr)+2*iColumnNum-1;
  928.                       switch (*pchPixelPtr)
  929.                         {
  930.                           case 'A':
  931.                             if (chPenColor != 'A')
  932.                               {
  933.                                 if (chPenColor != ' ')
  934.                                   GpiLine(hPS,&ptlStartingPosition);
  935.                                 chPenColor='A';
  936.                                 GpiSetColor(hPS,BACKTRACK_COLOR);
  937.                                 GpiMove(hPS,&ptlStartingPosition);
  938.                               }
  939.                             break;
  940.                           case 'S':
  941.                             if (chPenColor != 'S')
  942.                               {
  943.                                 if (chPenColor != ' ')
  944.                                   GpiLine(hPS,&ptlStartingPosition);
  945.                                 chPenColor='S';
  946.                                 GpiSetColor(hPS,SOLUTION_COLOR);
  947.                                 GpiMove(hPS,&ptlStartingPosition);
  948.                               }
  949.                             break;
  950.                           default:
  951.                             if (chPenColor != ' ')
  952.                               {
  953.                                 GpiLine(hPS,&ptlStartingPosition);
  954.                                 chPenColor=' ';
  955.                               }
  956.                             break;
  957.                         }
  958.                       ptlStartingPosition.y=ptlEndingPosition.y;
  959.                       ptlEndingPosition.y+=(*piTwiceMagnitudeDeltaX);
  960.                       if (ptlEndingPosition.y > *piYMax)
  961.                         ptlEndingPosition.y=*piYMax;
  962.                     }
  963.                   iEven=! iEven;
  964.                   prrCurrentPtr=prrCurrentPtr->prrSuccessorPtr;
  965.                 }
  966.               if (chPenColor != ' ')
  967.                 GpiLine(hPS,&ptlStartingPosition);
  968.               ptlStartingPosition.x+=(*piMagnitudeDeltaX);
  969.               ptlEndingPosition.x=ptlStartingPosition.x;
  970.             }
  971.           ptlStartingPosition.x=*piXMax;
  972.           ptlEndingPosition.x=*piXMax;
  973.           ptlStartingPosition.y=0;
  974.           ptlEndingPosition.y=*piYMax;
  975.           GpiSetColor(hPS,WALL_COLOR);
  976.           GpiMove(hPS,&ptlStartingPosition);
  977.           GpiLine(hPS,&ptlEndingPosition);
  978.         }
  979.       return;
  980.     }
  981.  
  982. static void DestroyMaze(pprrRowHead,pprrRowTail)
  983.   pROWREC *pprrRowHead;
  984.   pROWREC *pprrRowTail;
  985.     {
  986.       pROWREC prrPreviousPtr;
  987.  
  988.       while (*pprrRowHead != NULL)
  989.         {
  990.           free((*pprrRowHead)->pchRowPtr);
  991.           prrPreviousPtr=*pprrRowHead;
  992.           *pprrRowHead=(*pprrRowHead)->prrSuccessorPtr;
  993.           free((char *) prrPreviousPtr);
  994.         }
  995.       *pprrRowTail=NULL;
  996.       return;
  997.     }
  998.  
  999. static void ClearPaths(pprrRowHead,piNumColumns)
  1000.   pROWREC *pprrRowHead;
  1001.   int     *piNumColumns;
  1002.     {
  1003.       int     iX;
  1004.       pROWREC prrCurrentPtr;
  1005.  
  1006.       prrCurrentPtr=*pprrRowHead;
  1007.       while (prrCurrentPtr != NULL)
  1008.         {
  1009.           for (iX=1; iX < 2*(*piNumColumns); iX++)
  1010.             if (*((prrCurrentPtr->pchRowPtr)+iX) != 'W')
  1011.               *((prrCurrentPtr->pchRowPtr)+iX)=' ';
  1012.           prrCurrentPtr=prrCurrentPtr->prrSuccessorPtr;
  1013.         }
  1014.       *(((*pprrRowHead)->pchRowPtr)+1)='S';
  1015.       *((((*pprrRowHead)->prrSuccessorPtr)->pchRowPtr)+1)='S';
  1016.       return;
  1017.     }
  1018.  
  1019. static void OptionallyHaveComputerSolve(pprrRowHead,pprrRowTail,
  1020.  piDeltaX,piDeltaY,piNumColumns,piFatalError)
  1021.   pROWREC *pprrRowHead;
  1022.   pROWREC *pprrRowTail;
  1023.   int     *piDeltaX;
  1024.   int     *piDeltaY;
  1025.   int     *piNumColumns;
  1026.   int     *piFatalError;
  1027.     {
  1028.       int           iFinished;
  1029.       int           iRecurse;
  1030.       int           iX;
  1031.       int           iXNext;
  1032.       pROWREC       prrCurrentPtr;
  1033.       pROWREC       prrNextPtr;
  1034.       pSTACK1REC    ps1StackHead;
  1035.       pSTACK1REC    ps1StackPtr;
  1036.       unsigned char uchDeltaIndex1;
  1037.  
  1038.       iX=1;
  1039.       prrCurrentPtr=(*pprrRowHead)->prrSuccessorPtr;
  1040.       prrNextPtr=prrCurrentPtr->prrSuccessorPtr;
  1041.       iFinished=FALSE;
  1042.       iRecurse=TRUE;
  1043.       ps1StackHead=NULL;
  1044.       while ((! iFinished) && (! *piFatalError))
  1045.         {
  1046.           if (iRecurse)
  1047.             {
  1048.               uchDeltaIndex1=0;
  1049.               iRecurse=FALSE;
  1050.             };
  1051.           while ((uchDeltaIndex1 < 4)
  1052.           &&     (! iFinished)
  1053.           &&     (! iRecurse)
  1054.           &&     (! *piFatalError))
  1055.             {
  1056.               switch (*(piDeltaY+(24*uchDeltaIndex1)))
  1057.                 {
  1058.                   case -1:
  1059.                     iXNext=iX;
  1060.                     prrNextPtr=prrCurrentPtr->prrPredecessorPtr;
  1061.                     break;
  1062.                   case 1:
  1063.                     iXNext=iX;
  1064.                     prrNextPtr=prrCurrentPtr->prrSuccessorPtr;
  1065.                     break;
  1066.                   default:
  1067.                     prrNextPtr=prrCurrentPtr;
  1068.                     iXNext=iX+(*(piDeltaX+(24*uchDeltaIndex1)));
  1069.                     break;
  1070.                 }
  1071.               if (*((prrNextPtr->pchRowPtr)+iXNext) == ' ')
  1072.                 {
  1073.                   *((prrNextPtr->pchRowPtr)+iXNext)='S';
  1074.                   switch (*(piDeltaY+(24*uchDeltaIndex1)))
  1075.                     {
  1076.                       case -1:
  1077.                         prrNextPtr=prrNextPtr->prrPredecessorPtr;
  1078.                         break;
  1079.                       case 1:
  1080.                         prrNextPtr=prrNextPtr->prrSuccessorPtr;
  1081.                         break;
  1082.                       default:
  1083.                         iXNext+=(*(piDeltaX+(24*uchDeltaIndex1)));
  1084.                         break;
  1085.                     }
  1086.                   if (prrNextPtr != NULL)
  1087.                     {
  1088.                       *((prrNextPtr->pchRowPtr)+iXNext)='S';
  1089.                       iX=iXNext;
  1090.                       prrCurrentPtr=prrNextPtr;
  1091.                       if ((ps1StackPtr=(struct STACK1REC *) malloc(
  1092.                        (unsigned) sizeof(struct STACK1REC)))
  1093.                        == NULL)
  1094.                         *piFatalError=TRUE;
  1095.                       else
  1096.                         {
  1097.                           ps1StackPtr->ps1NextPtr=ps1StackHead;
  1098.                           ps1StackHead=ps1StackPtr;
  1099.                           ps1StackHead->chIndex1
  1100.                            =uchDeltaIndex1;
  1101.                           iRecurse=TRUE;
  1102.                         }
  1103.                     }
  1104.                   else
  1105.                     iFinished=TRUE;
  1106.                 }
  1107.               else
  1108.                 uchDeltaIndex1++;
  1109.             };
  1110.           if ((uchDeltaIndex1 >= 4) && (! *piFatalError))
  1111.             {
  1112.               *((prrCurrentPtr->pchRowPtr)+iX)=' ';
  1113.               iXNext=iX;
  1114.               prrNextPtr=prrCurrentPtr;
  1115.               uchDeltaIndex1=ps1StackHead->chIndex1;
  1116.               ps1StackPtr=ps1StackHead;
  1117.               ps1StackHead=ps1StackHead->ps1NextPtr;
  1118.               free((char *) ps1StackPtr);
  1119.               switch (*(piDeltaY+(24*uchDeltaIndex1)))
  1120.                 {
  1121.                   case -1:
  1122.                     prrCurrentPtr=prrCurrentPtr->prrSuccessorPtr;
  1123.                     *((prrCurrentPtr->pchRowPtr)+iX)=' ';
  1124.                     prrCurrentPtr=prrCurrentPtr->prrSuccessorPtr;
  1125.                     break;
  1126.                   case 1:
  1127.                     prrCurrentPtr=prrCurrentPtr->prrPredecessorPtr;
  1128.                     *((prrCurrentPtr->pchRowPtr)+iX)=' ';
  1129.                     prrCurrentPtr=prrCurrentPtr->prrPredecessorPtr;
  1130.                     break;
  1131.                   default:
  1132.                     iX-=(*(piDeltaX+(24*uchDeltaIndex1)));
  1133.                     *((prrCurrentPtr->pchRowPtr)+iX)=' ';
  1134.                     iX-=(*(piDeltaX+(24*uchDeltaIndex1)));
  1135.                     break;
  1136.                 }
  1137.               uchDeltaIndex1++;
  1138.             }
  1139.         };
  1140.       if (! *piFatalError)
  1141.        *(((*pprrRowTail)->pchRowPtr)+(2*(*piNumColumns)-1))='S';
  1142.       while (ps1StackHead != NULL)
  1143.         {
  1144.           ps1StackPtr=ps1StackHead;
  1145.           ps1StackHead=ps1StackHead->ps1NextPtr;
  1146.           free((char *) ps1StackPtr);
  1147.         }
  1148.       return;
  1149.     }
  1150.